package com.duxiaochang.weatherapp;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatSpinner;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private AppCompatSpinner mSpinner;
    private ArrayAdapter<String> mSpAdapter;
    private  String[] mCities;

    private TextView tvWeather,tvTem,tvTemLowHigh,tvWin,tvAir;
    private ImageView ivWeather;
    private RecyclerView rvlFutureWeather;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //调用
        initView();
    }

    private void initView() {
        /**
         * mSpAdapter控件绑定
         */
        //拿到
        mSpinner=findViewById(R.id.sp_city);
        //  数据关联或者是id资源的关联(点击的时候确定对象的)
        mCities=getResources().getStringArray(R.array.cities);
        // 列表需要适配器跟其数据进行关联
        mSpAdapter=new ArrayAdapter<>(MainActivity.this,R.layout.sp_item_layout,mCities);
        mSpinner.setAdapter(mSpAdapter);

        //下拉数据设置点击事件
        mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            //控件选中调用,默认选中第一条,位置position=0
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            }

            @Override
            //控件未选中调用
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        /**
         * 简单控件绑定
          */
        tvWeather=findViewById(R.id.tv_weather);
        tvTem=findViewById(R.id.tv_tem);
        tvTemLowHigh=findViewById(R.id.tv_tem_low_high);
        tvWin=findViewById(R.id.tv_win);
        tvAir=findViewById(R.id.tv_air);
        ivWeather=findViewById(R.id.iv_weather);
        rvlFutureWeather=findViewById(R.id.rlv_future_weather);

    }
}